<template>
	<view>
		<view class="box">
			<image :src="loginbanner" class="sign-banner" alt=""></image>
			<image :src="loginlogo" class="sign-logo" alt=""></image>
			<view class="sign-box">
				<h3>修改密码</h3>
				<view class="same-btn password ">
					<label style="width: 220rpx; padding: 0 10px; color: #333;">旧密码</label>
					<input type="password" v-model="oldPassword" id="password" placeholder="请输入旧密码">
				</view>
				<view class="same-btn password ">
					<label style="width: 220rpx; padding: 0 10px; color: #333;">新密码</label>
					<input type="password" v-model="Password" id="password" placeholder="请输入新密码(不少于6个字符)">
				</view>
				<view class="same-btn password passwordtwo">
					<label style="width: 220rpx; padding: 0 10px; color: #333;">确认密码</label>
					<input type="password" v-model="newPassword" id="password" placeholder="再次输入新密码">
				</view>
				<u-button type="primary" class="sign-btn" @click="onSubmit">确定</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '@/common/js/config.js'
	import helper from '@/common/js/helper.js'
	export default {
		data() {
			return {
				lookpwd: true,
				load: false,
				oldPassword: '',
				Password: '',
				newPassword: '',
				user: {
					oldPassword: "",
					password: ""
				},
				loginbanner: config.Resources.banner.loginbanner,
				loginlogo: config.Resources.banner.loginlogo
			}
		},
		onLoad(e) {
			try {
				const userProvider = uni.getStorageSync(config.Global.cache + '_UserProvider');
			} catch (e) {}
		},
		methods: {
			/* 表单提交 */
			onSubmit() {
				if (this.Password != this.newPassword) {
					helper.msg('两次密码不一致，重新输入');
					return;
				}
				this.user.oldPassword = helper.calcuMD5(this.oldPassword);
				this.user.password = helper.calcuMD5(this.newPassword);
				this.$helper.ajax({
					url: '/api/Permission/Users/Current/Actions/ModifyPasswordMoble',
					method: 'POST',
					contentType: "application/json",
					data: this.user,
					success: res => {
						uni.showModal({
							title: '修改成功，请重新登录',
							icon: "success",
							showCancel: false,
							confirmText: '我知道了',
							success: () => {
								uni.redirectTo({
									url: '/pages/users/sign-in/sign-in'
								});
							}
						});
					}
				});
			},
		}
	}
</script>

<style>
	.password {
		margin-bottom: 40upx;
	}

	.company {
		margin-bottom: 40upx;
	}

	.passwordtwo {
		margin-bottom: 170upx;
	}
</style>